<?php
	/**
	 * Crypt :: two-way encryption class using RIJNDAEL 256 AES standard
	 * @uses MCRYPT_RIJNDAEL_256
	 */
	class Crypt
	{
		private $key,$iv_size,$iv;
	 
		/**
		 * constructor
		 * @param $key (string:'DefaultKey')
		 * @return void
		 */
		function __construct($key='DefaultKey'){
			$this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
			$this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
			$this->key = trim($key);
		}
		
		public function encrypt($string){
			$string=trim($string);
			return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $string, MCRYPT_MODE_ECB, $this->iv));
		}
	 
		public function decrypt($string){
			return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$this->key,base64_decode($string),MCRYPT_MODE_ECB,$this->iv));
		}
	}
	
	// How to use !!
	$crypt = new Crypt('1');	// set manual key
	echo $crypt->encrypt('1').'<br/>'; // encrypt
	echo $crypt->decrypt('BhXByjnrRxkOpZvzS71ggDrgbhDCoPrS94VqobUktis='); // decrypt
	
	
?>